﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Website/Site1.Master" AutoEventWireup="true" %>
<%@ Import Namespace="ChicagoDealsN" %>
<%@ Import Namespace="System.Data" %>
<%@ Register TagPrefix="myControls" Namespace="myControls" Assembly="EmailBox"%>
<%@ Register TagPrefix="myControls" Namespace="myControls" Assembly="StatesDropDownList"%>

<script  language = "c#" runat="server">
    public void Page_Load(object sender, EventArgs e)
    {
        //  RESTRICT USER FROM ACCESSING THIS PAGE UNLESS USER IS LOGGED IN !
        if (!IsLoggedIn())
            Response.Redirect("/website/Default.aspx");
        else 
        {
            confirmation.Text = (Session["UserDet"] as DataUser).User_Name +", You can edit your profile here.";    
        }
    
        if (!IsPostBack)
        {
            try
            {
                int itemID = getId();
                string id = Request.QueryString["User_Id"];
                confirmation.Text = "Value = " + id;

             //  BizUser myBizObject = new BizUser();

               // DataTable dt = myBizObject.BLGetUserById(itemID);

                    txtName.Text = (Session["UserDet"] as DataUser).User_Name;
                    txtPassword.Text = (Session["UserDet"] as DataUser).Password;
                    txtAddress.Text = (Session["Userdet"] as DataUser).User_Address;
                    txtEmail.Text = (Session["Userdet"] as DataUser).Email_Id;
                    txtCc1.Text = (Session["Userdet"] as DataUser).Credit_Card_Number;
                   
                
               // }

            }
            catch (Exception ex)
            {
                //confirmationmessage.Text = "<h3>Invalid request</h1><br/>" + e + "<br/><br/>";
            }

        }
                
    }
    public void Button_Submit(Object s, EventArgs e)
    {
     try
        {

            BizUser bu = new BizUser();
            //string ccNo;
            
            int UserId = (Session["Userdet"] as DataUser).User_Id;
            string Gender = rbGender.SelectedItem.Value;
            //string ccNo = txtCc1.Text;// +txtCc2.Text + txtCc3.Text + txtCc4.Text;

            bool c = bu.BLUpdateAccount(UserId, txtPassword.Text, txtName.Text, txtAddress.Text, txtEmail.Text, txtCc1.Text, Convert.ToChar(Gender));
            if (c)
            {
                string message = "<br>Your Details are updated!";
                confirmation.Text = message;

                (Session["UserDet"] as DataUser).User_Name = txtName.Text;
                (Session["Userdet"] as DataUser).Password = txtPassword.Text;
                (Session["Userdet"] as DataUser).User_Address = txtAddress.Text;
                (Session["Userdet"] as DataUser).Email_Id = txtEmail.Text;
                (Session["Userdet"] as DataUser).Credit_Card_Number = txtCc1.Text;
                (Session["Userdet"] as DataUser).Gender = rbGender.SelectedItem.Value;
            }
            else
            {
                string message1 = "<br>error!!";
                confirmation.Text = message1;
            }
        }
        catch (Exception exp) { confirmation.Text = exp.ToString(); }
              
        
    }
    
    private bool IsLoggedIn()
    {
        return (Session["UserDet"] != null) ? true : false;
    }

    private int getId()
    {
        return (Session["UserDet"] as DataUser).User_Id;
    }
    
 </script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
<div id="conirmation-container">
       <asp:Label id="confirmation" runat="server" />
       <br/>
</div>

<div id="Div1"><asp:Label ID="Label1" runat="server" /></div>
 <table cellpadding="8" cellspacing="5">
    <tr>
        <td>User Name:</td>
        <td><asp:TextBox id="txtName" Runat="Server" /></td>
    </tr>
    <tr>
        <td>Password :</td>
        <td><asp:Textbox id="txtPassword" Runat="Server" /></td>
    </tr>
    <tr>
        <td>Address:</td>
        <td><asp:Textbox id="txtAddress" Runat="Server" /></td>
    </tr>
    <tr>
        <td>Email:</td>
        <td><myControls:EmailBox Runat="Server" id="txtEmail" Required="true"/></td>
    </tr>
    <tr>
        <td>Credi card Number :</td>
        <td>
            <asp:Textbox id="txtCc1" Runat="Server" MaxLength="16" Width="120"/>
           <!-- <asp:Textbox id="txtCc2" Runat="Server" MaxLength="4" Width="30"/>-
            <asp:Textbox id="txtCc3" Runat="Server" MaxLength="4" Width="30"/>-
            <asp:Textbox id="txtCc4" Runat="Server" MaxLength="4" Width="30"/> -->
        </td>
    </tr>
    <tr>
        <td>Gender :</td>
        <td>
            <asp:RadioButtonList ID="rbGender" runat="server">
                <asp:ListItem Text="Male" Value="M" Selected="true"></asp:ListItem>
                <asp:ListItem Text="Female" Value="F"></asp:ListItem>
            </asp:RadioButtonList>
        </td>
    </tr>
    <tr>
        <td>&nbsp;
        </td>
        <td><asp:Button ID="Button" Text="Submit" OnClick="Button_Submit" Runat="Server" /></td>
    </tr>
 </table>



</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
